﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;
using System.Web;

namespace DTO
{
    public class Globals
    {
        static Globals()
        {}

        public readonly static WebAppSection Settings = (WebAppSection)WebConfigurationManager.GetSection("WebApp");

        public static string ThemesSelectorID = "";

        public static string ApplicationPath
        {
            get
            { 
                string url= HttpContext.Current.Request.ApplicationPath;
                if (url.EndsWith("/"))
                    return url;
                else
                    return url + "/";
            }
        }

        public static string ServerHostName
        {
            get
            {
                string serverHostName = "";
                string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
                if (port == null || port == "80" || port == "443")
                {
                    port = "";
                }
                else
                {
                    port = ":" + port;
                }

                string protocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
                if (protocol == null || protocol == "0")
                {
                    protocol = "http://";
                }
                else
                {
                    protocol = "https://";
                }

                serverHostName = protocol + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port;
                if(serverHostName.EndsWith("/"))
                    return serverHostName;
                return serverHostName + "/";
            }
        }

        public static string PhysicalApplicationPath
        {
            get
            {
                string url = HttpContext.Current.Request.PhysicalApplicationPath;
                if (url.EndsWith("/"))
                    return url;
                else
                    return url + "/";
            }
        }

        public static string ImageUrl()
        {
            try
            {
                return ApplicationPath + "Images/";
            }
            catch
            {
                return "";
            }
        }

    }
}
